package com.mo.axion.handler.config;

import com.mo.axion.common.pipeline.ProcessController;
import com.mo.axion.common.pipeline.ProcessTemplate;
import com.mo.axion.handler.action.DeduplicationAction;
import com.mo.axion.handler.action.DiscardAction;
import com.mo.axion.handler.action.SendMessageAction;
import com.mo.axion.handler.action.ShieldAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Mo
 * @createTime 2024/2/17 17:26
 * @description handler层的pipeline配置类
 */
@Slf4j
@Configuration
public class TaskPipelineConfig {
    public static final String PIPELINE_HANDLER_CODE = "handler";

    @Autowired
    private DiscardAction discardAction;

    @Autowired
    private ShieldAction shieldAction;

    @Autowired
    private DeduplicationAction deduplicationAction;

    @Autowired
    private SendMessageAction sendMessageAction;

    @Bean("taskTemplate")
    public ProcessTemplate taskTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        processTemplate.setProcessList(Arrays.asList(
                discardAction,
                shieldAction,
//                deduplicationAction,
                sendMessageAction
        ));
        log.info("Initialized PipelineAction for TaskPipelineConfig:" + processTemplate.getProcessList());
        return processTemplate;
    }

    /**
     *
     * @return
     */
    @Bean("handlerProcessController")
    public ProcessController processController() {
        ProcessController processController = new ProcessController();
        Map<String, ProcessTemplate> templateConfig = new HashMap<>(4);
        templateConfig.put(PIPELINE_HANDLER_CODE, taskTemplate());
        processController.setTemplateConfig(templateConfig);
        log.info("handlerProcessController初始化完成， msg:{}", processController);
        return processController;
    }


}
